package com.btex.app.adapter;

import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.widget.TextView;

import com.btex.app.MyApplication;
import com.btex.app.R;
import com.btex.app.entity.MakeListInfo;
import com.btex.app.tools.SharedPreferencesUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/5/18
 * @time 下午3:29
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class DogeFragmentAdapter extends BaseQuickAdapter<MakeListInfo.DataBean.DOGEBean, BaseViewHolder> {

    public DogeFragmentAdapter(@Nullable List<MakeListInfo.DataBean.DOGEBean> data) {
        super(R.layout.item_first_fragmnet, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MakeListInfo.DataBean.DOGEBean item) {

        String amount_float_num = item.getAmount_float_num();
        int i = Integer.parseInt(amount_float_num);

        Log.i("kehfuwDogeFragmentAdap", "" + i);

        SharedPreferencesUtil sharedPreferences = SharedPreferencesUtil.getSharedPreferences(MyApplication.getContextObject());
        boolean isEngilsh = sharedPreferences.getBoolean("isEngilsh", false);
        if (isEngilsh) {
            helper.setText(R.id.item_trade_money, "$" + item.getTicker().getRate_price_u());

        } else {
            helper.setText(R.id.item_trade_money, "￥" + item.getTicker().getRate_price_c());
        }

//        helper.addOnClickListener(R.id.fragment_first_imag_type);
        helper.addOnClickListener(R.id.fragment_first_lin_type);
        helper.setText(R.id.item_trade_price, item.getTicker().getTrade_price());
        helper.setText(R.id.item_trade_type, item.getType());
        String change_24h = item.getTicker().getChange_24h();
        if (change_24h.contains(",")) {
            String replace = change_24h.replace(",", "");
            change_24h = replace;
        }


//        if (aDouble > 0) {
//            helper.setBackgroundRes(R.id.item_trade_zhang_die, R.color.bg_green);
//            int length = String.valueOf(v).length();
//            if (length > 4) {
//                helper.setText(R.id.item_trade_zhang_die, "+" + String.valueOf(v).substring(0, 4) + "%");
//            } else {
//                helper.setText(R.id.item_trade_zhang_die, "+" + String.valueOf(v) + "%");
//            }
//        } else {
//            helper.setBackgroundRes(R.id.item_trade_zhang_die, R.color.bg_red);
//            int length = String.valueOf(v).length();
//            if (length > 4) {
//                helper.setText(R.id.item_trade_zhang_die, String.valueOf(v).substring(0, 5) + "%");
//            } else {
//                helper.setText(R.id.item_trade_zhang_die, String.valueOf(v) + "%");
//            }
//        }

        boolean ischengjiao = sharedPreferences.getBoolean("ischengjiao", false);

        if (ischengjiao) {

            helper.setBackgroundRes(R.id.item_trade_zhang_die, R.color.white);
            helper.setText(R.id.item_trade_zhang_die, item.getTicker().getAmount().substring(0, i));
            helper.setTextColor(R.id.item_trade_zhang_die, MyApplication.getContextObject().getResources().getColor(R.color.tv_black_light));
            TextView textView = (TextView) helper.getView(R.id.item_trade_zhang_die);
            textView.setTypeface(Typeface.DEFAULT_BOLD);


        } else {

            if (!TextUtils.isEmpty(change_24h)) {


                Double aDouble = Double.valueOf(change_24h);
                double v = aDouble * 100;
                helper.setTextColor(R.id.item_trade_zhang_die, MyApplication.getContextObject().getResources().getColor(R.color.white));
                if (aDouble > 0) {
                    helper.setBackgroundRes(R.id.item_trade_zhang_die, R.drawable.item_bg_no);
                    int length = String.valueOf(v).length();
                    if (length > 4) {
                        helper.setText(R.id.item_trade_zhang_die, "+" + String.valueOf(v).substring(0, 4) + "%");
                    } else {
                        helper.setText(R.id.item_trade_zhang_die, "+" + String.valueOf(v) + "%");
                    }
                } else {
                    helper.setBackgroundRes(R.id.item_trade_zhang_die, R.drawable.item_bg);
                    int length = String.valueOf(v).length();
                    if (length > 4) {
                        helper.setText(R.id.item_trade_zhang_die, String.valueOf(v).substring(0, 5) + "%");
                    } else {
                        helper.setText(R.id.item_trade_zhang_die, String.valueOf(v) + "%");
                    }
                }

            }
        }

        int collect_id = item.getCollect_id();

        if (collect_id > 0) {
            helper.setBackgroundRes(R.id.fragment_first_imag_type, R.mipmap.xuanze);

        } else {
            helper.setBackgroundRes(R.id.fragment_first_imag_type, R.mipmap.xuan_zhe_mo);
        }


    }
}
